#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    ListNode* GetMid(ListNode* head)
    {
        ListNode* slow, * fast;
        slow = fast = head;
        while (fast != nullptr && fast->next != nullptr)
        {
            slow = slow->next;
            fast = fast->next->next;
        }
        return slow;
    }
    ListNode* reverselist(ListNode* head)
    {
        ListNode* pre = nullptr;
        while (head != nullptr)
        {
            ListNode* Next = head->next;
            head->next = pre;
            pre = head;
            head = Next;
        }
        return pre;
    }
    void reorderList(ListNode* head)
    {
        if (head == nullptr)
            return;
        ListNode* Mid = GetMid(head);
        ListNode* l1 = head;
        ListNode* l2 = Mid->next;
        Mid->next = nullptr;
        l2 = reverselist(l2);

        while (l2 != nullptr)
        {
            ListNode* Next1 = l1->next;
            l1->next = l2;
            l1 = Next1;

            ListNode* Next2 = l2->next;
            l2->next = l1;
            l2 = Next2;
        }
    }
};

